{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4bd513ab",
   "metadata": {},
   "source": [
    "# 列表的语法：\n",
    "* 1.list.append(object)——在列表末尾添加新的对象\n",
    "* 2.list.count(object)——统计某个元素在列表中出现的次数\n",
    "* 3.list.extend(seq)——在列表末尾一次性追加另外一个序列中的多个值（用于新列表扩展原来的列表）\n",
    "* 4.list.index(object)——从列表中找出某个值第一个匹配项的索引位置\n",
    "* 5.list.insert(index,object)——将对象插入列表\n",
    "* 6.list.pop(index=-1)——移除列表中的一个元素（默认最后一个元素），并且返回该元素的值\n",
    "* 7.list.remove()——反方向列表中元素"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9733159c",
   "metadata": {},
   "source": [
    "# 1.append（增加）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "08e95c6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "060e5a14",
   "metadata": {},
   "outputs": [],
   "source": [
    "list.append(2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f4134051",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc', 2022]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "039bc631",
   "metadata": {},
   "source": [
    "# 2.count（计数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dedda1e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'abc',123,]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "52ec67ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.count(123)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5d52a6b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.count('abc')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d58f5540",
   "metadata": {},
   "source": [
    "# 3.extend（扩展）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "adc1b12b",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7f478594",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[2022,'zbl']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "852634ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "list.extend(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fa663bf8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2022, 'zbl', 2022, 'zbl']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dccc36a1",
   "metadata": {},
   "source": [
    "# 4.index（索引）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "84229155",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'zbl','abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "6b983933",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.index('zbl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95229acf",
   "metadata": {},
   "source": [
    "# 5.insert（插入）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4b3f5416",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c4edd2de",
   "metadata": {},
   "outputs": [],
   "source": [
    "list.insert(2,2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6fff7b53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc', 2022]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14330c0f",
   "metadata": {},
   "source": [
    "# 6.pop（移除——默认最后一个元素）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "49bca63f",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=['a','b','c',]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2c3af8f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "list2=list.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "fde95d97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'b'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2 # 删除的项为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "de940d78",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'c']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list # 列表现在是"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6016e53",
   "metadata": {},
   "source": [
    "# 7.remove（移除——某个值的第一个匹配项）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5741ee36",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[123,'zbl','abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "49dea5b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "list.remove('zbl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "bad69693",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e597eeea",
   "metadata": {},
   "source": [
    "| 列表的方法 | Description | 使用方法 | 备注 |\n",
    "| ---------- | ----------- | -------- | ---- | \n",
    "| append | 增加——在列表末尾添加新的对象 | list.append(object) | 无 |\n",
    "| ------ | ------------------------------ | ------------------- | -- |          \n",
    "| count | 计数——统计某个元素在列表中出现的次数 | list.count(object) | 无 |\n",
    "| ------ | ---------------------------------- | --------------- | ___ |                         \n",
    "| extend | 扩展——在列表末尾一次性追加另外一个列表中的多个值 | list.extend(seq) | 用于新列表扩展原来的列表 |\n",
    "| ------ | --------------------------------------------------------------- | ---------------------- |\n",
    "| index | 索引——从列表中找出某个值第一个匹配项的索引位置 | list.index(object) | 无 |\n",
    "| --- | ---------------------------------------------- | ---------------- | -- |\n",
    "|insert|插入——将对象插入列表|list.index(object)|无|\n",
    "| ---- | -------------------- | ---------------- | -- |\n",
    "|pop | 移除——移除列表中的一个元素（默认最后一个元素），并且返回该元素的值 | list=list1.pop(a) | a为元素在列表中的位置 |\n",
    "| ---- | --------------------------------------------------------------- | ---------------- |\n",
    "| remove | 移除——移除列表中某个值的第一个匹配项 | list.remove(object) | 无 |"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
